#include "../inc/link.h"

//建立带头节点的双向循环链表
floor_info *init_floor_list(void)
{
    //楼梯链表头节点
    floor_info *floor_head = (floor_info *)malloc(sizeof(floor_info));
    if(floor_head != NULL)
    {
        //初始化链表头节点
        INIT_LIST_HEAD(&floor_head->floor_list);
        return floor_head;
    }

    printf("分配楼层头节点内存失败\n");
    return NULL;
}
adver_info *init_adver_list(void)
{
    //广告链表头节点
    adver_info *adver_head = (adver_info *)malloc(sizeof(adver_info));
    if(adver_head != NULL)
    {
        //初始化链表头节点
        INIT_LIST_HEAD(&adver_head->adver_list);
        return adver_head;
    }

    printf("分配广告头节点内存失败\n");
    return NULL;
}


// 创建新节点
floor_info *create_floor_node(char *floorimg,int i)
{ 
    //楼层新节点
    floor_info *floor_new = (floor_info *)malloc(sizeof(floor_info));
    if(floor_new != NULL)
    {
        //初始化节点
        strcpy(floor_new->floorimg , floorimg[i]);//给新链表赋值当前楼层图片
        floor_new->current_floor = i;//给新链表赋值当前楼层
        INIT_LIST_HEAD(&floor_new->floor_list);//初始化
        
        return floor_new;
    }
    printf("创建新楼层节点失败\n");
    return NULL;
}
adver_info *create_adver_node(char *adverimg ,int i)
{ 
    //广告新节点
    adver_info *adver_new = (adver_info *)malloc(sizeof(adver_info));
    if(adver_new != NULL)
    {
        //初始化节点
        strcpy(adver_new->adverimg , adverimg[i]);//给新链表赋值当前广告图片
        adver_new->current_adver = i;//当前播放的广告

        INIT_LIST_HEAD(&adver_new->adver_list);

        return adver_new;
    }
    printf("创建新广告节点失败\n");
    return NULL;
}

//尾插法
//因为有头节点，所以不需要返回头指针
void list_tail_floor(floor_info *floor_head, floor_info *floor_new,adver_info *adver_head,adver_info *adver_new)
{
    //楼层链表尾插法
    list_add_tail(&floor_new->floor_list, &floor_head->floor_list.prev); 
    //广告链表尾插法
    list_add_tail(&adver_new->adver_list, &adver_head->adver_list.prev);
}



//遍历显示楼层图片(jpg)
void list_show_floor(floor_info *floor_head)
{
    floor_info *p = NULL;
    list_for_each_entry(p, &floor_head->floor_list, floor_list)
    {
        
    }
}
